﻿@using ERP.WebUI
@model PermissionModel
@{
    ViewBag.Title = ViewBag.CurrentTitle;
    var editButton = new ButtonModel();
    var deleteButton = new ButtonModel();
    editButton = ViewBag.Edit;
    deleteButton = ViewBag.Delete;
    var createButton = new ButtonModel();
    createButton = ViewBag.Create;
}

<div id="content-body" class="row-fluid">
    <div class="span22">
        <!--操作 -->
        <div class="widget-box">
            <div class="widget-title">
                <span class="icon"><i class="icon-search"></i></span>
                <h5>操作</h5>
            </div>
            <div class="widget-content nopadding">
                <form class="form-horizontal search-form" method="post" name="basic_validate" novalidate="novalidate">
                    <div class="form-actions form-operate text-right" style="border-top: 0;">
                        @if (createButton != null)
                        {
                            <button type="button" class="btn btn-primary" onclick="Create()">
                                <span class="@createButton.Icon"></span>@createButton.Text
                            </button>
                        }
                    </div>
                </form>
            </div>
        </div>


        <!--列表-->
        <div class="widget-box">
            <div class="widget-title">
                <span class="icon"><i class="icon-th"></i></span>
                <h5>权限列表</h5>
            </div>
            <div class="widget-content nopadding">
                <table class="table table-bordered data-table">
                    <thead>
                        <tr>
                            <th width="5%">序号</th>
                            <th width="18%">权限（按钮）名称</th>
                            <th width="15%">编码</th>
                            <th width="8%">图标</th>
                            <th width="8%">排序</th>
                            <th width="20%">描述</th>
                            <th width="10%">是否激活</th>
                            <th width="17%">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>

    </div>
</div>

@section scripts{
    <script type="text/javascript">
        var oTable = null;
        $(function () {
            var actionUrl = "@Url.Action("List")?rand=" + Math.random();
            var aoColumns = [
                    { "sName": "SortId", "bSortable": false },
                    { "sName": "Name", "bSortable": false },
                    { "sName": "Code", "bSortable": false },
                    {
                        "sName": "icon",
                        "bSortable": false,
                        "fnRender": function (oObj) {
                            return '<i class="' + oObj.aData[3] + '"></i>';
                        }
                    },
                    { "sName": "OrderSort", "bSortable": false },
                    { "sName": "Description", "bSortable": false },
                    { "sName": "Enabled", "bSortable": false },
                    {
                        "sName": "Id",
                        "bSortable": false,
                        "fnRender": function (oObj) {
                            var btnArray = "";
                            @if (editButton != null)
                            {
                                <text>btnArray += '<button type="submit" class="btn btn-primary btn-normal" title="@editButton.Text" onclick="Edit(' + oObj.aData[oObj.aData.length - 1] + ')"><span class="@editButton.Icon"></span></button>'</text>
                            }
                            @if (deleteButton != null)
                            {
                                <text>btnArray += '<button type="submit" class="btn btn-danger btn-normal" title="@deleteButton.Text" onclick="Delete(' + oObj.aData[oObj.aData.length - 1] + ')"><span class="@deleteButton.Icon"></span></button>'</text>
                            }
                            return btnArray;
                        }
                    }
            ];
            //初始化表格
            oTable = InitDatatables($(".data-table"), actionUrl, aoColumns, oTable);
        });

        //查询
        function Search() {
            var filterdata = $(".search-form").serialize();
            oTable.fnReloadAjax("@Url.Action("List")?rand=" + Math.random() + "&" + filterdata);
        }

        //新增
        function Create() {
            var actionUrl = "@Url.Action("Create")";
            location.href = actionUrl;
        }

        //编辑
        function Edit(id) {
            var actionUrl = "@Url.Action("Edit")"+"/"+id;
            location.href = actionUrl;
        }

        //删除
        function Delete(id) {
            var actionUrl = "@Url.Action("Delete")";
            var param = { Id: id }
            DeleteRecord(actionUrl, param, oTable);
        }

    </script>
}